package com.example.module_enterprise.view


import android.graphics.Color
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.module_enterprise.R
import com.example.module_enterprise.adapter.EnterpriseDetailAdapter
import com.example.module_enterprise.databinding.ActivityDetailEnterBinding
import com.example.module_enterprise.vm.EnterpriseViewModel
import com.yuwei.base.BaseActivity
import com.yuwei.common.path.RouterPath
import com.yuwei.http.entity.EnterpriseEntityItem
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = RouterPath.DETAIL_ENTERPRISE)
class DetailEnterActivity : BaseActivity<ActivityDetailEnterBinding,EnterpriseViewModel>() {
    private val enterpriseDetailAdapter = EnterpriseDetailAdapter()
    @Autowired
    lateinit var enter:EnterpriseEntityItem
    override fun initView() {
        ARouter.getInstance().inject(this)
        binding.enterpriseDetailBack.setOnClickListener {
            finish()
        }
        binding.enterDetailName.text = enter.name
        binding.enterDetailType.text = enter.industryType
        binding.enterDetailAddress.text = enter.address
        binding.enterDetailFdName.text = enter.legalRepresentative
        binding.enterDetailPhone.text = enter.contactInfo
        if (enter.status == "运营中"){
            binding.enterDetailZt.text = enter.status
            binding.enterDetailZt.setTextColor(Color.parseColor("#16A34A"))
            binding.enterDetailZt.setBackgroundResource(R.drawable.enter_detail_bg1)
        }else{
            binding.enterDetailZt.text = enter.status
            binding.enterDetailZt.setTextColor(Color.parseColor("#EF4444"))
            binding.enterDetailZt.setBackgroundResource(R.drawable.enter_detail_bg2)
        }
        binding.enterDetailRv.adapter = enterpriseDetailAdapter
        binding.enterDetailRv.layoutManager = LinearLayoutManager(this)
        vm.getDetailEnterpriseList(enter.id)
        binding.enterDetailSs.text = "已上市"
        binding.enterDetailGpName.text = enter.stockName
        binding.enterDetailGpNum.text = enter.stockCode




    }

    override fun initData() {
            vm.getDetailEnterpriseSuccess.observe(this){
                enterpriseDetailAdapter.data.clear()
                enterpriseDetailAdapter.data.addAll(it.photos)
                enterpriseDetailAdapter.notifyDataSetChanged()
            }



    }

}